﻿using System;
using System.Collections.Generic;
using System.Linq;
using Helpers;
using TaleWorlds.CampaignSystem.Actions;
using TaleWorlds.CampaignSystem.Conversation;
using TaleWorlds.CampaignSystem.MapEvents;
using TaleWorlds.CampaignSystem.Party;
using TaleWorlds.CampaignSystem.Settlements;
using TaleWorlds.Core;
using TaleWorlds.Library;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

namespace TaleWorlds.CampaignSystem.Issues
{
	// Token: 0x0200031D RID: 797
	public class TheConquestOfSettlementIssueBehavior : CampaignBehaviorBase
	{
		// Token: 0x06002DE6 RID: 11750 RVA: 0x000C0AAC File Offset: 0x000BECAC
		public override void RegisterEvents()
		{
			CampaignEvents.OnCheckForIssueEvent.AddNonSerializedListener(this, new Action<Hero>(this.OnCheckForIssue));
		}

		// Token: 0x06002DE7 RID: 11751 RVA: 0x000C0AC8 File Offset: 0x000BECC8
		private void OnCheckForIssue(Hero hero)
		{
			Settlement relatedObject;
			if (this.ConditionsHold(hero, out relatedObject))
			{
				Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(new PotentialIssueData.StartIssueDelegate(this.OnStartIssue), typeof(TheConquestOfSettlementIssueBehavior.TheConquestOfSettlementIssue), IssueBase.IssueFrequency.VeryCommon, relatedObject));
				return;
			}
			Campaign.Current.IssueManager.AddPotentialIssueData(hero, new PotentialIssueData(typeof(TheConquestOfSettlementIssueBehavior.TheConquestOfSettlementIssue), IssueBase.IssueFrequency.VeryCommon));
		}

		// Token: 0x06002DE8 RID: 11752 RVA: 0x000C0B30 File Offset: 0x000BED30
		private bool ConditionsHold(Hero issueGiver, out Settlement targetSettlement)
		{
			targetSettlement = null;
			if (issueGiver.IsLord && issueGiver.MapFaction.IsKingdomFaction && issueGiver.IsFactionLeader && !issueGiver.IsPrisoner && issueGiver.GetMapPoint() != null)
			{
				if (issueGiver.Clan.Settlements.Any((Settlement x) => x.IsFortification))
				{
					MBList<Settlement> mblist = new MBList<Settlement>();
					foreach (Town town in Campaign.Current.AllTowns)
					{
						if (town.MapFaction.IsAtWarWith(issueGiver.MapFaction) && town.Settlement.Position2D.DistanceSquared(issueGiver.GetMapPoint().Position2D) < 7500f)
						{
							mblist.Add(town.Settlement);
						}
					}
					foreach (Town town2 in Campaign.Current.AllCastles)
					{
						if (town2.MapFaction.IsAtWarWith(issueGiver.MapFaction) && town2.Settlement.Position2D.DistanceSquared(issueGiver.GetMapPoint().Position2D) < 7500f)
						{
							mblist.Add(town2.Settlement);
						}
					}
					if (mblist.Count > 0)
					{
						targetSettlement = mblist.GetRandomElement<Settlement>();
					}
				}
			}
			return targetSettlement != null;
		}

		// Token: 0x06002DE9 RID: 11753 RVA: 0x000C0CDC File Offset: 0x000BEEDC
		private IssueBase OnStartIssue(in PotentialIssueData pid, Hero issueOwner)
		{
			PotentialIssueData potentialIssueData = pid;
			return new TheConquestOfSettlementIssueBehavior.TheConquestOfSettlementIssue(issueOwner, (Settlement)potentialIssueData.RelatedObject);
		}

		// Token: 0x06002DEA RID: 11754 RVA: 0x000C0D02 File Offset: 0x000BEF02
		public override void SyncData(IDataStore dataStore)
		{
		}

		// Token: 0x04000DB3 RID: 3507
		private const IssueBase.IssueFrequency TheConquestOfSettlementIssueFrequency = IssueBase.IssueFrequency.VeryCommon;

		// Token: 0x02000677 RID: 1655
		public class TheConquestOfSettlementIssue : IssueBase
		{
			// Token: 0x060053CA RID: 21450 RVA: 0x0017AC51 File Offset: 0x00178E51
			internal static void AutoGeneratedStaticCollectObjectsTheConquestOfSettlementIssue(object o, List<object> collectedObjects)
			{
				((TheConquestOfSettlementIssueBehavior.TheConquestOfSettlementIssue)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x060053CB RID: 21451 RVA: 0x0017AC5F File Offset: 0x00178E5F
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._targetSettlement);
			}

			// Token: 0x060053CC RID: 21452 RVA: 0x0017AC74 File Offset: 0x00178E74
			internal static object AutoGeneratedGetMemberValue_targetSettlement(object o)
			{
				return ((TheConquestOfSettlementIssueBehavior.TheConquestOfSettlementIssue)o)._targetSettlement;
			}

			// Token: 0x170011CD RID: 4557
			// (get) Token: 0x060053CD RID: 21453 RVA: 0x0017AC81 File Offset: 0x00178E81
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=mvzh0HVk}The Conquest of {TARGET_SETTLEMENT}", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x170011CE RID: 4558
			// (get) Token: 0x060053CE RID: 21454 RVA: 0x0017ACA8 File Offset: 0x00178EA8
			public override TextObject Description
			{
				get
				{
					TextObject textObject = new TextObject("{=xeZR3r5u}{QUEST_GIVER.LINK} wants you siege and take over the {TARGET_SETTLEMENT}", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170011CF RID: 4559
			// (get) Token: 0x060053CF RID: 21455 RVA: 0x0017ACF1 File Offset: 0x00178EF1
			public override TextObject IssueBriefByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=Oi20UrO2}Our war with the {TARGET_SETTLEMENT_FACTION_INFORMAL_NAME} is going well enough. But there are some who say that we don't have enough to show for all the blood and silver we've spent. A clear victory at this stage would do a lot of good. I think I would like to see our banner flying from the towers of {TARGET_SETTLEMENT}.[ib:normal2][if:convo_thinking]", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT_FACTION_INFORMAL_NAME", this._targetSettlement.MapFaction.InformalName);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x170011D0 RID: 4560
			// (get) Token: 0x060053D0 RID: 21456 RVA: 0x0017AD34 File Offset: 0x00178F34
			public override TextObject IssueAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=qKrUyqsD}Of course, my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}. But sieges are always costly...", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.IssueOwner.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170011D1 RID: 4561
			// (get) Token: 0x060053D1 RID: 21457 RVA: 0x0017AD68 File Offset: 0x00178F68
			public override TextObject IssueQuestSolutionExplanationByIssueGiver
			{
				get
				{
					TextObject textObject = new TextObject("{=yf3NVFi0}Yes, they are. That's why I am offering you the sum of {REWARD_GOLD}{GOLD_ICON} if you can take {TARGET_SETTLEMENT} within {TIME_LIMIT} days.[if:convo_thinking] I count you among the most resourceful of my captains. I think you can do this, with courage, Heaven's favor and a bit of luck. Can I tell my other lords that you will do this?", null);
					textObject.SetTextVariable("REWARD_GOLD", this.RewardGold);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					textObject.SetTextVariable("TIME_LIMIT", 60);
					return textObject;
				}
			}

			// Token: 0x170011D2 RID: 4562
			// (get) Token: 0x060053D2 RID: 21458 RVA: 0x0017ADB7 File Offset: 0x00178FB7
			public override TextObject IssueQuestSolutionAcceptByPlayer
			{
				get
				{
					TextObject textObject = new TextObject("{=scmTEn90}You may tell them. {TARGET_SETTLEMENT} will be ours within 60 days.", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x170011D3 RID: 4563
			// (get) Token: 0x060053D3 RID: 21459 RVA: 0x0017ADDB File Offset: 0x00178FDB
			public override bool IsThereAlternativeSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x170011D4 RID: 4564
			// (get) Token: 0x060053D4 RID: 21460 RVA: 0x0017ADDE File Offset: 0x00178FDE
			public override bool IsThereLordSolution
			{
				get
				{
					return false;
				}
			}

			// Token: 0x170011D5 RID: 4565
			// (get) Token: 0x060053D5 RID: 21461 RVA: 0x0017ADE1 File Offset: 0x00178FE1
			protected override int RewardGold
			{
				get
				{
					return 20000;
				}
			}

			// Token: 0x060053D6 RID: 21462 RVA: 0x0017ADE8 File Offset: 0x00178FE8
			public TheConquestOfSettlementIssue(Hero issueOwner, Settlement targetSettlement) : base(issueOwner, CampaignTime.DaysFromNow(60f))
			{
				this._targetSettlement = targetSettlement;
			}

			// Token: 0x060053D7 RID: 21463 RVA: 0x0017AE02 File Offset: 0x00179002
			protected override float GetIssueEffectAmountInternal(IssueEffect issueEffect)
			{
				if (issueEffect == DefaultIssueEffects.SettlementSecurity)
				{
					return -1f;
				}
				if (issueEffect == DefaultIssueEffects.SettlementLoyalty)
				{
					return -1f;
				}
				return 0f;
			}

			// Token: 0x060053D8 RID: 21464 RVA: 0x0017AE25 File Offset: 0x00179025
			protected override void OnGameLoad()
			{
			}

			// Token: 0x060053D9 RID: 21465 RVA: 0x0017AE27 File Offset: 0x00179027
			protected override void HourlyTick()
			{
			}

			// Token: 0x060053DA RID: 21466 RVA: 0x0017AE29 File Offset: 0x00179029
			protected override QuestBase GenerateIssueQuest(string questId)
			{
				return new TheConquestOfSettlementIssueBehavior.TheConquestOfSettlementIssueQuest(questId, base.IssueOwner, this._targetSettlement, CampaignTime.DaysFromNow(60f), this.RewardGold);
			}

			// Token: 0x060053DB RID: 21467 RVA: 0x0017AE4D File Offset: 0x0017904D
			public override IssueBase.IssueFrequency GetFrequency()
			{
				return IssueBase.IssueFrequency.VeryCommon;
			}

			// Token: 0x060053DC RID: 21468 RVA: 0x0017AE50 File Offset: 0x00179050
			protected override bool CanPlayerTakeQuestConditions(Hero issueGiver, out IssueBase.PreconditionFlags flags, out Hero relationHero, out SkillObject skill)
			{
				relationHero = null;
				skill = null;
				flags = IssueBase.PreconditionFlags.None;
				if (issueGiver.GetRelationWithPlayer() < -10f)
				{
					flags |= IssueBase.PreconditionFlags.Relation;
					relationHero = issueGiver;
				}
				if (issueGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
				{
					flags |= IssueBase.PreconditionFlags.AtWar;
				}
				if (Clan.PlayerClan.Kingdom != issueGiver.MapFaction)
				{
					flags |= IssueBase.PreconditionFlags.NotInSameFaction;
				}
				if (Clan.PlayerClan.IsUnderMercenaryService)
				{
					flags |= IssueBase.PreconditionFlags.ClanIsMercenary;
				}
				return flags == IssueBase.PreconditionFlags.None;
			}

			// Token: 0x060053DD RID: 21469 RVA: 0x0017AED4 File Offset: 0x001790D4
			public override bool IssueStayAliveConditions()
			{
				if (this._targetSettlement.MapFaction.IsAtWarWith(base.IssueOwner.MapFaction) && base.IssueOwner.MapFaction.IsKingdomFaction)
				{
					return base.IssueOwner.Clan.Settlements.Any((Settlement x) => x.IsFortification);
				}
				return false;
			}

			// Token: 0x060053DE RID: 21470 RVA: 0x0017AF46 File Offset: 0x00179146
			protected override void CompleteIssueWithTimedOutConsequences()
			{
			}

			// Token: 0x04001B3B RID: 6971
			private const int QuestTimeLimit = 60;

			// Token: 0x04001B3C RID: 6972
			[SaveableField(10)]
			private Settlement _targetSettlement;
		}

		// Token: 0x02000678 RID: 1656
		public class TheConquestOfSettlementIssueQuest : QuestBase
		{
			// Token: 0x060053DF RID: 21471 RVA: 0x0017AF48 File Offset: 0x00179148
			internal static void AutoGeneratedStaticCollectObjectsTheConquestOfSettlementIssueQuest(object o, List<object> collectedObjects)
			{
				((TheConquestOfSettlementIssueBehavior.TheConquestOfSettlementIssueQuest)o).AutoGeneratedInstanceCollectObjects(collectedObjects);
			}

			// Token: 0x060053E0 RID: 21472 RVA: 0x0017AF56 File Offset: 0x00179156
			protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
			{
				base.AutoGeneratedInstanceCollectObjects(collectedObjects);
				collectedObjects.Add(this._targetSettlement);
			}

			// Token: 0x060053E1 RID: 21473 RVA: 0x0017AF6B File Offset: 0x0017916B
			internal static object AutoGeneratedGetMemberValue_targetSettlement(object o)
			{
				return ((TheConquestOfSettlementIssueBehavior.TheConquestOfSettlementIssueQuest)o)._targetSettlement;
			}

			// Token: 0x170011D6 RID: 4566
			// (get) Token: 0x060053E2 RID: 21474 RVA: 0x0017AF78 File Offset: 0x00179178
			public override TextObject Title
			{
				get
				{
					TextObject textObject = new TextObject("{=mvzh0HVk}The Conquest of {TARGET_SETTLEMENT}", null);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x170011D7 RID: 4567
			// (get) Token: 0x060053E3 RID: 21475 RVA: 0x0017AF9C File Offset: 0x0017919C
			public override bool IsRemainingTimeHidden
			{
				get
				{
					return false;
				}
			}

			// Token: 0x170011D8 RID: 4568
			// (get) Token: 0x060053E4 RID: 21476 RVA: 0x0017AFA0 File Offset: 0x001791A0
			private TextObject QuestStartedLog
			{
				get
				{
					TextObject textObject = new TextObject("{=b1T6qywr}{QUEST_GIVER.LINK} from {QUEST_GIVER.FACTION} asked you to take over {TARGET_SETTLEMENT} in the name of {QUEST_GIVER.FACTION} to fortify war efforts. {QUEST_GIVER.LINK} said {?QUEST_GIVER.GENDER}she{?}he{\\?} will aid you with {REWARD}{GOLD_ICON} once the {TARGET_SETTLEMENT} is fallen.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, true);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					textObject.SetTextVariable("REWARD", this.RewardGold);
					return textObject;
				}
			}

			// Token: 0x170011D9 RID: 4569
			// (get) Token: 0x060053E5 RID: 21477 RVA: 0x0017AFFC File Offset: 0x001791FC
			private TextObject WarDeclaredQuestCancelLog
			{
				get
				{
					TextObject textObject = new TextObject("{=PakhagOy}Your clan is now at war with {QUEST_GIVER.LINK}'s lord. Your agreement with {QUEST_GIVER.LINK} was canceled.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170011DA RID: 4570
			// (get) Token: 0x060053E6 RID: 21478 RVA: 0x0017B030 File Offset: 0x00179230
			private TextObject PlayerDeclaredWarQuestLogText
			{
				get
				{
					TextObject textObject = new TextObject("{=bqeWVVEE}Your actions have started a war with {QUEST_GIVER.LINK}'s faction. {?QUEST_GIVER.GENDER}She{?}He{\\?} cancels your agreement and the quest is a failure.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170011DB RID: 4571
			// (get) Token: 0x060053E7 RID: 21479 RVA: 0x0017B064 File Offset: 0x00179264
			private TextObject QuestTimeOutFailLog
			{
				get
				{
					TextObject textObject = new TextObject("{=lEcg67Qk}You have failed to take over {TARGET_SETTLEMENT} in time. {QUEST_GIVER.LINK} is disappointed that you have failed to take the fortress in time.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x170011DC RID: 4572
			// (get) Token: 0x060053E8 RID: 21480 RVA: 0x0017B0B0 File Offset: 0x001792B0
			private TextObject QuestSuccessLog
			{
				get
				{
					TextObject textObject = new TextObject("{=6d2VIgH3}{QUEST_GIVER.LINK}: Thank you. My lords see you as an example, and see your conquest of {TARGET_SETTLEMENT} as be a stepping stone toward further victories. {?QUEST_GIVER.GENDER}She{?}He{\\?} is grateful for your service and gave you {REWARD}{GOLD_ICON}.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					textObject.SetTextVariable("REWARD", this.RewardGold);
					return textObject;
				}
			}

			// Token: 0x170011DD RID: 4573
			// (get) Token: 0x060053E9 RID: 21481 RVA: 0x0017B10C File Offset: 0x0017930C
			private TextObject QuestLesserSuccessLog
			{
				get
				{
					TextObject textObject = new TextObject("{=1NtZ4BJh}{QUEST_GIVER.LINK}: Thank you. My lords see the conquest of {TARGET_SETTLEMENT} was a stepping stone toward further victories. {?QUEST_GIVER.GENDER}She{?}He{\\?} is grateful for your service. Because you didn't lead the army {?QUEST_GIVER.GENDER}She{?}He{\\?} gave you {LESSER_REWARD}{GOLD_ICON} of denars.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x170011DE RID: 4574
			// (get) Token: 0x060053EA RID: 21482 RVA: 0x0017B158 File Offset: 0x00179358
			private TextObject TargetSettlementTakenByAnotherFaction
			{
				get
				{
					TextObject textObject = new TextObject("{=diUtbbaH}{TARGET_SETTLEMENT} is taken by {NEW_OWNER_FACTION}. Your agreement with {QUEST_GIVER.LINK} is no longer valid.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x170011DF RID: 4575
			// (get) Token: 0x060053EB RID: 21483 RVA: 0x0017B1A4 File Offset: 0x001793A4
			private TextObject TargetSettlementTakenByPlayerFaction
			{
				get
				{
					TextObject textObject = new TextObject("{=bEak0k5N}{TARGET_SETTLEMENT} is taken. You did not participate in this battle. Your agreement with {QUEST_GIVER.LINK} is moot.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x170011E0 RID: 4576
			// (get) Token: 0x060053EC RID: 21484 RVA: 0x0017B1F0 File Offset: 0x001793F0
			private TextObject LeftFaction
			{
				get
				{
					TextObject textObject = new TextObject("{=d8TeoRNf}You are no longer in the same faction with {QUEST_GIVER.LINK}. Your agreement with {QUEST_GIVER.LINK} is no longer valid.", null);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					return textObject;
				}
			}

			// Token: 0x170011E1 RID: 4577
			// (get) Token: 0x060053ED RID: 21485 RVA: 0x0017B224 File Offset: 0x00179424
			private TextObject DefectedToAnotherFaction
			{
				get
				{
					TextObject textObject = new TextObject("{=8iVkBa6D}{TARGET_SETTLEMENT_OWNER.LINK} has defected to {FACTION_NAME} along with {TARGET_SETTLEMENT}. Your agreement with {QUEST_GIVER.LINK} is moot.", null);
					StringHelpers.SetCharacterProperties("TARGET_SETTLEMENT_OWNER", this._targetSettlement.OwnerClan.Leader.CharacterObject, textObject, false);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, false);
					textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
					return textObject;
				}
			}

			// Token: 0x170011E2 RID: 4578
			// (get) Token: 0x060053EE RID: 21486 RVA: 0x0017B290 File Offset: 0x00179490
			private TextObject NoLongerEnemy
			{
				get
				{
					TextObject textObject = new TextObject("{=HknxaCpK}{TARGET_SETTLEMENT_OWNER.FACTION} and {QUEST_GIVER.FACTION} had made peace. Your agreement with {QUEST_GIVER.LINK} is moot.", null);
					StringHelpers.SetCharacterProperties("TARGET_SETTLEMENT_OWNER", this._targetSettlement.OwnerClan.Leader.CharacterObject, textObject, true);
					StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject, true);
					return textObject;
				}
			}

			// Token: 0x060053EF RID: 21487 RVA: 0x0017B2E4 File Offset: 0x001794E4
			public TheConquestOfSettlementIssueQuest(string questId, Hero questGiver, Settlement targetSettlement, CampaignTime duration, int rewardGold) : base(questId, questGiver, duration, rewardGold)
			{
				this._targetSettlement = targetSettlement;
				this.SetDialogs();
				base.InitializeQuestOnCreation();
			}

			// Token: 0x060053F0 RID: 21488 RVA: 0x0017B308 File Offset: 0x00179508
			protected override void SetDialogs()
			{
				this.OfferDialogFlow = DialogFlow.CreateDialogFlow("issue_classic_quest_start", 100).NpcLine(new TextObject("{=QP3BbOW3}Very good. You have my blessing to summon an army if you wish, or, if you prefer to strike quickly, you may do so on your own...[ib:hip][if:convo_mocking_aristocratic]", null), null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).Consequence(new ConversationSentence.OnConsequenceDelegate(this.QuestAcceptedConsequences)).CloseDialog();
				TextObject textObject = new TextObject("{=ICNtSonV}How are your preparations to take {TARGET_SETTLEMENT} coming along, {PLAYER.NAME}? I have assured my other lords that you will take it, so it will look bad if you fail.", null);
				textObject.SetTextVariable("TARGET_SETTLEMENT", this._targetSettlement.Name);
				TextObject textObject2 = new TextObject("{=m4pZhnyd}They are going as planned, my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}...", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject2, false);
				TextObject textObject3 = new TextObject("{=jFXkosnJ}This may be tricky, my {?QUEST_GIVER.GENDER}lady{?}lord{\\?}...", null);
				StringHelpers.SetCharacterProperties("QUEST_GIVER", base.QuestGiver.CharacterObject, textObject3, false);
				this.DiscussDialogFlow = DialogFlow.CreateDialogFlow("quest_discuss", 100).NpcLine(textObject, null, null).Condition(() => Hero.OneToOneConversationHero == base.QuestGiver).BeginPlayerOptions().PlayerOption(textObject2, null).NpcLine(new TextObject("{=opMDusHz}Good. I look forward to presenting you with your reward.", null), null, null).Consequence(delegate
				{
					Campaign.Current.ConversationManager.ConversationEndOneShot += MapEventHelper.OnConversationEnd;
				}).CloseDialog().PlayerOption(textObject3, null).NpcLine(new TextObject("{=R85IMErK}Well, if you fail we will deal with that, but I would prefer not to.", null), null, null).Consequence(delegate
				{
					Campaign.Current.ConversationManager.ConversationEndOneShot += MapEventHelper.OnConversationEnd;
				}).CloseDialog().EndPlayerOptions();
			}

			// Token: 0x060053F1 RID: 21489 RVA: 0x0017B484 File Offset: 0x00179684
			private void QuestAcceptedConsequences()
			{
				base.StartQuest();
				base.AddLog(this.QuestStartedLog, false);
				base.AddTrackedObject(this._targetSettlement);
			}

			// Token: 0x060053F2 RID: 21490 RVA: 0x0017B4A6 File Offset: 0x001796A6
			protected override void HourlyTick()
			{
			}

			// Token: 0x060053F3 RID: 21491 RVA: 0x0017B4A8 File Offset: 0x001796A8
			protected override void RegisterEvents()
			{
				CampaignEvents.WarDeclared.AddNonSerializedListener(this, new Action<IFaction, IFaction, DeclareWarAction.DeclareWarDetail>(this.OnWarDeclared));
				CampaignEvents.OnClanChangedKingdomEvent.AddNonSerializedListener(this, new Action<Clan, Kingdom, Kingdom, ChangeKingdomAction.ChangeKingdomActionDetail, bool>(this.OnClanChangedKingdom));
				CampaignEvents.MapEventStarted.AddNonSerializedListener(this, new Action<MapEvent, PartyBase, PartyBase>(this.OnMapEventStarted));
				CampaignEvents.SiegeCompletedEvent.AddNonSerializedListener(this, new Action<Settlement, MobileParty, bool, MapEvent.BattleTypes>(this.OnSiegeCompleted));
				CampaignEvents.OnSettlementOwnerChangedEvent.AddNonSerializedListener(this, new Action<Settlement, bool, Hero, Hero, Hero, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail>(this.OnSettlementOwnerChanged));
				CampaignEvents.MakePeace.AddNonSerializedListener(this, new Action<IFaction, IFaction, MakePeaceAction.MakePeaceDetail>(this.OnPeaceDeclared));
			}

			// Token: 0x060053F4 RID: 21492 RVA: 0x0017B53F File Offset: 0x0017973F
			private void OnPeaceDeclared(IFaction faction1, IFaction faction2, MakePeaceAction.MakePeaceDetail detail)
			{
				if (!base.QuestGiver.MapFaction.IsAtWarWith(this._targetSettlement.MapFaction))
				{
					base.CompleteQuestWithCancel(this.NoLongerEnemy);
				}
			}

			// Token: 0x060053F5 RID: 21493 RVA: 0x0017B56C File Offset: 0x0017976C
			private void OnSettlementOwnerChanged(Settlement settlement, bool openToClaim, Hero newOwner, Hero oldOwner, Hero capturerHero, ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail detail)
			{
				if (base.IsOngoing && settlement == this._targetSettlement)
				{
					if (newOwner == Hero.MainHero && detail == ChangeOwnerOfSettlementAction.ChangeOwnerOfSettlementDetail.ByBarter)
					{
						this.QuestSuccess(2);
						return;
					}
					if (newOwner.MapFaction != base.QuestGiver.MapFaction && !newOwner.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
					{
						TextObject targetSettlementTakenByAnotherFaction = this.TargetSettlementTakenByAnotherFaction;
						targetSettlementTakenByAnotherFaction.SetTextVariable("NEW_OWNER_FACTION", newOwner.MapFaction.EncyclopediaLinkWithName);
						base.CompleteQuestWithCancel(targetSettlementTakenByAnotherFaction);
					}
				}
			}

			// Token: 0x060053F6 RID: 21494 RVA: 0x0017B5F0 File Offset: 0x001797F0
			private void OnSiegeCompleted(Settlement siegeSettlement, MobileParty attackerParty, bool isWin, MapEvent.BattleTypes battleType)
			{
				if (isWin && siegeSettlement == this._targetSettlement)
				{
					if (attackerParty.MapFaction == base.QuestGiver.MapFaction)
					{
						if (attackerParty == MobileParty.MainParty)
						{
							this.QuestSuccess(10);
							return;
						}
						if (siegeSettlement.Party.MapEvent.InvolvedParties.Contains(PartyBase.MainParty))
						{
							this.QuestLesserSuccess();
							return;
						}
						base.CompleteQuestWithCancel(this.TargetSettlementTakenByPlayerFaction);
						return;
					}
					else
					{
						TextObject targetSettlementTakenByAnotherFaction = this.TargetSettlementTakenByAnotherFaction;
						targetSettlementTakenByAnotherFaction.SetTextVariable("NEW_OWNER_FACTION", attackerParty.MapFaction.EncyclopediaLinkWithName);
						base.CompleteQuestWithCancel(targetSettlementTakenByAnotherFaction);
					}
				}
			}

			// Token: 0x060053F7 RID: 21495 RVA: 0x0017B688 File Offset: 0x00179888
			private void QuestLesserSuccess()
			{
				TextObject questLesserSuccessLog = this.QuestLesserSuccessLog;
				int num = this.RewardGold / 4;
				questLesserSuccessLog.SetTextVariable("LESSER_REWARD", num);
				base.AddLog(questLesserSuccessLog, false);
				GainRenownAction.Apply(Hero.MainHero, 5f, false);
				GiveGoldAction.ApplyForQuestBetweenCharacters(null, Hero.MainHero, num, false);
				this.RelationshipChangeWithQuestGiver = 1;
				foreach (Settlement settlement in from x in base.QuestGiver.Clan.Settlements
				where x.IsFortification
				select x)
				{
					settlement.Town.Security += 2f;
					settlement.Town.Loyalty += 2f;
				}
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x060053F8 RID: 21496 RVA: 0x0017B778 File Offset: 0x00179978
			private void QuestSuccess(int boost)
			{
				base.AddLog(this.QuestSuccessLog, false);
				this.RelationshipChangeWithQuestGiver = 5;
				GiveGoldAction.ApplyForQuestBetweenCharacters(null, Hero.MainHero, this.RewardGold, false);
				foreach (Settlement settlement in from x in base.QuestGiver.Clan.Settlements
				where x.IsFortification
				select x)
				{
					settlement.Town.Security += (float)boost;
					settlement.Town.Loyalty += (float)boost;
				}
				base.CompleteQuestWithSuccess();
			}

			// Token: 0x060053F9 RID: 21497 RVA: 0x0017B840 File Offset: 0x00179A40
			private void OnMapEventStarted(MapEvent mapEvent, PartyBase attackerParty, PartyBase defenderParty)
			{
				if (QuestHelper.CheckMinorMajorCoercion(this, mapEvent, attackerParty))
				{
					QuestHelper.ApplyGenericMinorMajorCoercionConsequences(this, mapEvent);
				}
			}

			// Token: 0x060053FA RID: 21498 RVA: 0x0017B854 File Offset: 0x00179A54
			private void OnClanChangedKingdom(Clan clan, Kingdom oldKingdom, Kingdom newKingdom, ChangeKingdomAction.ChangeKingdomActionDetail detail, bool showNotification = true)
			{
				if (clan == Clan.PlayerClan && oldKingdom == base.QuestGiver.MapFaction)
				{
					base.AddLog(this.LeftFaction, false);
					base.CompleteQuestWithFail(null);
					return;
				}
				if (!clan.Settlements.Contains(this._targetSettlement))
				{
					if (base.QuestGiver.MapFaction.IsAtWarWith(Hero.MainHero.MapFaction))
					{
						base.CompleteQuestWithCancel(this.WarDeclaredQuestCancelLog);
					}
					return;
				}
				if (newKingdom == base.QuestGiver.MapFaction)
				{
					this.QuestSuccess(1);
					return;
				}
				TextObject defectedToAnotherFaction = this.DefectedToAnotherFaction;
				defectedToAnotherFaction.SetTextVariable("FACTION_NAME", newKingdom.EncyclopediaLinkWithName);
				base.CompleteQuestWithCancel(defectedToAnotherFaction);
			}

			// Token: 0x060053FB RID: 21499 RVA: 0x0017B8FF File Offset: 0x00179AFF
			private void OnWarDeclared(IFaction faction1, IFaction faction2, DeclareWarAction.DeclareWarDetail detail)
			{
				QuestHelper.CheckWarDeclarationAndFailOrCancelTheQuest(this, faction1, faction2, detail, this.PlayerDeclaredWarQuestLogText, this.WarDeclaredQuestCancelLog, false);
			}

			// Token: 0x060053FC RID: 21500 RVA: 0x0017B917 File Offset: 0x00179B17
			protected override void InitializeQuestOnGameLoad()
			{
				this.SetDialogs();
			}

			// Token: 0x060053FD RID: 21501 RVA: 0x0017B920 File Offset: 0x00179B20
			protected override void OnTimedOut()
			{
				base.AddLog(this.QuestTimeOutFailLog, false);
				this.RelationshipChangeWithQuestGiver = -10;
				foreach (Settlement settlement in from x in base.QuestGiver.Clan.Settlements
				where x.IsFortification
				select x)
				{
					settlement.Town.Security += -10f;
					settlement.Town.Loyalty += -10f;
				}
			}

			// Token: 0x04001B3D RID: 6973
			private const int SuccessLoyaltySecurityBoost = 10;

			// Token: 0x04001B3E RID: 6974
			private const int LesserSuccessLoyaltySecurityBoost = 2;

			// Token: 0x04001B3F RID: 6975
			private const int SuccessRelationBoost = 5;

			// Token: 0x04001B40 RID: 6976
			private const int LesserSuccessRelationBoost = 1;

			// Token: 0x04001B41 RID: 6977
			private const int TimeoutSecurityLoyaltyPenalty = -10;

			// Token: 0x04001B42 RID: 6978
			private const int TimeoutRelationyPenalty = -10;

			// Token: 0x04001B43 RID: 6979
			[SaveableField(10)]
			private Settlement _targetSettlement;
		}

		// Token: 0x02000679 RID: 1657
		public class TheConquestOfSettlementIssueTypeDefiner : SaveableTypeDefiner
		{
			// Token: 0x06005400 RID: 21504 RVA: 0x0017B9F6 File Offset: 0x00179BF6
			public TheConquestOfSettlementIssueTypeDefiner() : base(620000)
			{
			}

			// Token: 0x06005401 RID: 21505 RVA: 0x0017BA03 File Offset: 0x00179C03
			protected override void DefineClassTypes()
			{
				base.AddClassDefinition(typeof(TheConquestOfSettlementIssueBehavior.TheConquestOfSettlementIssue), 1, null);
				base.AddClassDefinition(typeof(TheConquestOfSettlementIssueBehavior.TheConquestOfSettlementIssueQuest), 2, null);
			}
		}
	}
}
